package com.wonders.qxmanager.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wonders.qxmanager.model.Organization;
import com.wonders.qxmanager.model.Team;
import com.wonders.qxmanager.service.OrganizationService;
import com.wonders.qxmanager.utils.PageArrayList;
import com.wonders.qxmanager.utils.PageUIHelper;
import com.wonders.qxmanager.utils.PageUIHelper.Page;

@Controller
public class OrganizationController {
	@Autowired
	OrganizationService orgService ;
	@RequestMapping("/org/save.do")
	public void save(Organization org, HttpServletRequest req, HttpServletResponse res)
			throws Exception {
		
		this.orgService.addOrga(org);
		JSONObject result=new JSONObject();
		result.put("success", true);
		PageUIHelper.writeFormResponse(res, result.toString());
		System.out.println(result.toString()+"================");
	}
	
	@RequestMapping("/org/list.do")
	public void list(HttpServletRequest req, HttpServletResponse res)
			throws IOException {
		Organization org = new Organization();
		Page page = PageUIHelper.getPage(req);
		PageArrayList<Organization> list = orgService.getListByPage(org, page);
		PageUIHelper.writeJsonResponse(res, PageUIHelper.toString(list));
	}

}
